1   /*
2    * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.
8    *
9    * This code is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12   * version 2 for more details (a copy is included in the LICENSE file that
13   * accompanied this code).
14   *
15   * You should have received a copy of the GNU General Public License version
16   * 2 along with this work; if not, write to the Free Software Foundation,
17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18   *
19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20   * or visit www.oracle.com if you need additional information or have any
21   * questions.
22   */
23  
24  /**
25   *
26   *
27   *  This isn't the test case: ResourceCheckTest.sh is.
28   *  Refer to ResourceCheckTest.sh when running this test.
29   *
30   *  @bug 5008856 5023573 5024917 5062569
31   *  @summary 'missing resource key' error for key = "Operating system"
32   */
33  
34  import java.awt.event.KeyEvent;
35  
36  import sun.tools.jconsole.Resources;
37  
38  public class ResourceCheckTest {
39  
40      public static void main(String[] args){
41          Object [][] testData = {
42              {"<", "", "", "", ""},
43              {"<<", "", "", "", ""},
44              {">", "", "", "", ""},
45              {" 1 day", "", "", "", ""},
46              {" 1 hour", "", "", "", ""},
47              {" 1 min", "", "", "", ""},
48              {" 1 month", "", "", "", ""},
49              {" 1 year", "", "", "", ""},
50              {" 2 hours", "", "", "", ""},
51              {" 3 hours", "", "", "", ""},
52              {" 3 months", "", "", "", ""},
53              {" 5 min", "", "", "", ""},
54              {" 6 hours", "", "", "", ""},
55              {" 6 months", "", "", "", ""},
56              {" 7 days", "", "", "", ""},
57              {"10 min", "", "", "", ""},
58              {"12 hours", "", "", "", ""},
59              {"30 min", "", "", "", ""},
60              {"ACTION", "", "", "", ""},
61              {"ACTION_INFO", "", "", "", ""},
62              {"All", "", "", "", ""},
63              {"Architecture", "", "", "", ""},
64              {"Attribute", "", "", "", ""},
65              {"Attribute value", "", "", "", ""},
66              {"Attribute values", "", "", "", ""},
67              {"Attributes", "", "", "", ""},
68              {"Blank", "", "", "", ""},
69              {"BlockedCount WaitedCount", "BlockedCount", "WaitedCount", "", ""},
70              {"Boot class path", "", "", "", ""},
71              {"BorderedComponent.moreOrLessButton.toolTip", "", "", "", ""},
72              {"Close", "", "", "", ""},
73              {"CPU Usage", "", "", "", ""},
74              {"CPUUsageFormat","PhonyPercentage", "", "", ""},
75              {"Cancel", "", "", "", ""},
76              {"Cascade", "", "", "", ""},
77              {"Cascade.mnemonic", "", "", "", ""},
78              {"Chart:", "", "", "", ""},
79              {"Chart:.mnemonic", "", "", "", ""},
80              {"ClassTab.infoLabelFormat", "LoadedCount", "UnloadedCount", "TotalCount", ""},
81              {"ClassTab.loadedClassesPlotter.accessibleName", "", "", "", ""},
82              {"Class path", "", "", "", ""},
83              {"Classes", "", "", "", ""},
84              {"ClassName", "", "", "", ""},
85              {"Column.Name", "", "", "", ""},
86              {"Column.PID", "", "", "", ""},
87              {"Committed", "", "", "", ""},
88              {"Committed memory", "", "", "", ""},
89              {"Committed virtual memory", "", "", "", ""},
90              {"Compiler", "", "", "", ""},
91              {"Connect...", "", "", "", ""},
92              {"Connect", "", "", "", ""},
93              {"Connect.mnemonic", "", "", "", ""},
94              {"ConnectDialog.connectButton.toolTip", "", "", "", ""},
95              {"ConnectDialog.accessibleDescription", "", "", "", ""},
96              {"ConnectDialog.masthead.accessibleName", "", "", "", ""},
97              {"ConnectDialog.masthead.title", "", "", "", ""},
98              {"ConnectDialog.statusBar.accessibleName", "", "", "", ""},
99              {"ConnectDialog.title", "", "", "", ""},
100             {"Connected. Click to disconnect.", "", "", "", ""},
101             {"connectingTo1", "PhonyConnectionName", "", "", ""},
102             {"connectingTo2", "PhonyConnectionName", "", "", ""},
103             {"connectionFailed1", "", "", "", ""},
104             {"connectionFailed2", "PhonyConnectionName", "", "", ""},
105             {"connectionLost1", "", "", "", ""},
106             {"connectionLost2", "PhonyConnectionName", "", "", ""},
107             {"Connection failed", "", "", "", ""},
108             {"Connection", "", "", "", ""},
109             {"Connection.mnemonic", "", "", "", ""},
110             {"Connection name", "", "", "", ""},
111             {"ConnectionName (disconnected)", "Phony", "Phony", "", ""},
112             {"Constructor", "", "", "", ""},
113             {"Create", "Phony", "Phony", "", ""},
114             {"Current classes loaded", "", "", "", ""},
115             {"Current heap size", "", "", "", ""},
116             {"Current value", "PhonyValue", "", "", ""},
117             {"Daemon threads", "", "", "", ""},
118             {"deadlockAllTab", "", "", "", ""},
119             {"deadlockTab", "", "", "", ""},
120             {"deadlockTabN", "PhonyInt", "", "", ""},
121             {"Description", "", "", "", ""},
122             {"Descriptor", "", "", "", ""},
123             {"Details", "", "", "", ""},
124             {"Detect Deadlock", "", "", "", ""},
125             {"Detect Deadlock.mnemonic", "", "", "", ""},
126             {"Detect Deadlock.toolTip", "", "", "", ""},
127             {"Dimension is not supported:", "", "", "", ""},
128             {"Discard chart", "", "", "", ""},
129             {"Disconnected. Click to connect.", "", "", "", ""},
130             {"Double click to expand/collapse", "", "", "", ""},
131             {"Double click to visualize", "", "", "", ""},
132             {"DurationDaysHoursMinutes", 0, 13, 54, ""},
133             {"DurationDaysHoursMinutes", 1, 13, 54, ""},
134             {"DurationDaysHoursMinutes", 2, 13, 54, ""},
135             {"DurationDaysHoursMinutes", 1024, 13, 45, ""},
136             {"DurationHoursMinutes", 0, 13, "", ""},
137             {"DurationHoursMinutes", 1, 0, "", ""},
138             {"DurationHoursMinutes", 1, 1, "", ""},
139             {"DurationHoursMinutes", 2, 42, "", ""},
140             {"DurationMinutes", 0, "", "", ""},
141             {"DurationMinutes", 1, "", "", ""},
142             {"DurationMinutes", 2, "", "", ""},
143             {"DurationSeconds", 0, "", "", ""},
144             {"DurationSeconds", 1, "", "", ""},
145             {"DurationSeconds", 2, "", "", ""},
146             {"Empty array", "", "", "", ""},
147             {"Error", "", "", "", ""},
148             {"Error: MBeans already exist", "", "", "", ""},
149             {"Error: MBeans do not exist", "", "", "", ""},
150             {"Event", "", "", "", ""},
151             {"Exit", "", "", "", ""},
152             {"Exit.mnemonic", "", "", "", ""},
153             {"expand", "", "", "", ""},
154             {"Fail to load plugin", "", "", "", ""},
155             {"FileChooser.fileExists.cancelOption", "", "", "", ""},
156             {"FileChooser.fileExists.message", "PhonyFileName", "", "", ""},
157             {"FileChooser.fileExists.okOption", "", "", "", ""},
158             {"FileChooser.fileExists.title", "", "", "", ""},
159             {"FileChooser.savedFile", "PhonyFilePath", "PhonyFileSize", "", ""},
160             {"FileChooser.saveFailed.message", "PhonyFilePath", "PhonyMessage", "", ""},
161             {"FileChooser.saveFailed.title", "", "", "", ""},
162             {"Free physical memory", "", "", "", ""},
163             {"Free swap space", "", "", "", ""},
164             {"Garbage collector", "", "", "", ""},
165             {"GC time", "", "", "", ""},
166             {"GC time details", 54, "Phony", 11, ""},
167             {"GcInfo", "Phony", -1, 768, ""},
168             {"GcInfo", "Phony", 0, 768, ""},
169             {"GcInfo", "Phony", 1, 768, ""},
170             {"Heap", "", "", "", ""},
171             {"Heap Memory Usage", "", "", "", ""},
172             {"Help.AboutDialog.accessibleDescription", "", "", "", ""},
173             {"Help.AboutDialog.jConsoleVersion", "DummyVersion", "", "", ""},
174             {"Help.AboutDialog.javaVersion", "DummyVersion", "", "", ""},
175             {"Help.AboutDialog.masthead.accessibleName", "", "", "", ""},
176             {"Help.AboutDialog.masthead.title", "", "", "", ""},
177             {"Help.AboutDialog.title", "", "", "", ""},
178             {"Help.AboutDialog.userGuideLink", "DummyMessage", "", "", ""},
179             {"Help.AboutDialog.userGuideLink.mnemonic", "", "", "", ""},
180             {"Help.AboutDialog.userGuideLink.url", "DummyURL", "", "", ""},
181             {"HelpMenu.About.title", "", "", "", ""},
182             {"HelpMenu.About.title.mnemonic", "", "", "", ""},
183             {"HelpMenu.UserGuide.title", "", "", "", ""},
184             {"HelpMenu.UserGuide.title.mnemonic", "", "", "", ""},
185             {"HelpMenu.title", "", "", "", ""},
186             {"HelpMenu.title.mnemonic", "", "", "", ""},
187             {"Hotspot MBeans...", "", "", "", ""},
188             {"Hotspot MBeans....mnemonic", "", "", "", ""},
189             {"Hotspot MBeans.dialog.accessibleDescription", "", "", "", ""},
190             {"Impact", "", "", "", ""},
191             {"Info", "", "", "", ""},
192             {"INFO", "", "", "", ""},
193             {"Invalid plugin path", "", "", "", ""},
194             {"Invalid URL", "", "", "", ""},
195             {"Is", "", "", "", ""},
196             {"Java Monitoring & Management Console", "", "", "", ""},
197             {"Java Virtual Machine", "", "", "", ""},
198             {"JConsole: ", "", "", "", ""},
199             {"JConsole.accessibleDescription", "", "", "", ""},
200             {"JConsole version", "PhonyVersion", "", "", ""},
201             {"JIT compiler", "", "", "", ""},
202             {"Library path", "", "", "", ""},
203             {"Live Threads", "", "", "", ""},
204             {"Loaded", "", "", "", ""},
205             {"Local Process:", "", "", "", ""},
206             {"Local Process:.mnemonic", "", "", "", ""},
207             {"Manage Hotspot MBeans in: ", "", "", "", ""},
208             {"Management Not Enabled", "", "", "", ""},
209             {"Management Will Be Enabled", "", "", "", ""},
210             {"Masthead.font", "", "", "", ""},
211             {"Max", "", "", "", ""},
212             {"Max", "", "", "", ""},
213             {"Maximum heap size", "", "", "", ""},
214             {"MBeanAttributeInfo", "", "", "", ""},
215             {"MBeanInfo", "", "", "", ""},
216             {"MBeanNotificationInfo", "", "", "", ""},
217             {"MBeanOperationInfo", "", "", "", ""},
218             {"MBeans", "", "", "", ""},
219             {"MBeansTab.clearNotificationsButton", "", "", "", ""},
220             {"MBeansTab.clearNotificationsButton.mnemonic", "", "", "", ""},
221             {"MBeansTab.clearNotificationsButton.toolTip", "", "", "", ""},
222             {"MBeansTab.compositeNavigationMultiple", 0, 0, "", ""},
223             {"MBeansTab.compositeNavigationSingle", "", "", "", ""},
224             {"MBeansTab.refreshAttributesButton", "", "", "", ""},
225             {"MBeansTab.refreshAttributesButton.mnemonic", "", "", "", ""},
226             {"MBeansTab.refreshAttributesButton.toolTip", "", "", "", ""},
227             {"MBeansTab.subscribeNotificationsButton", "", "", "", ""},
228             {"MBeansTab.subscribeNotificationsButton.mnemonic", "", "", "", ""},
229             {"MBeansTab.subscribeNotificationsButton.toolTip", "", "", "", ""},
230             {"MBeansTab.tabularNavigationMultiple", 0, 0, "", ""},
231             {"MBeansTab.tabularNavigationSingle", "", "", "", ""},
232             {"MBeansTab.unsubscribeNotificationsButton", "", "", "", ""},
233             {"MBeansTab.unsubscribeNotificationsButton.mnemonic", "", "", "", ""},
234             {"MBeansTab.unsubscribeNotificationsButton.toolTip", "", "", "", ""},
235             {"Memory", "", "", "", ""},
236             {"MemoryPoolLabel", "PhonyMemoryPool", "", "", ""},
237             {"MemoryTab.heapPlotter.accessibleName", "", "", "", ""},
238             {"MemoryTab.infoLabelFormat", "UsedCount", "CommittedCount", "MaxCount", ""},
239             {"MemoryTab.nonHeapPlotter.accessibleName", "", "", "", ""},
240             {"MemoryTab.poolChart.aboveThreshold", "Threshold", "", "", ""},
241             {"MemoryTab.poolChart.accessibleName", "", "", "", ""},
242             {"MemoryTab.poolChart.belowThreshold", "Threshold", "", "", ""},
243             {"MemoryTab.poolPlotter.accessibleName", "PhonyMemoryPool", "", "", ""},
244             {"Message", "", "", "", ""},
245             {"Method successfully invoked", "", "", "", ""},
246             {"Monitor locked", "", "", "", ""},
247             {"Minimize All", "", "", "", ""},
248             {"Minimize All.mnemonic", "", "", "", ""},
249             {"Name", "", "", "", ""},
250             {"Name and Build", "PhonyName", "PhonyBuild", "", ""},
251             {"Name Build and Mode", "PhonyName", "PhonyBuild", "PhonyMode", ""},
252             {"Name State", "PhonyName", "PhonyState", "", ""},
253             {"Name State LockName", "PhonyName", "PhonyState", "PhonyLock", ""},
254             {"Name State LockName LockOwner", "PhonyName", "PhonyState", "PhonyLock", "PhonyOwner"},
255             {"New Connection...", "", "", "", ""},
256             {"New Connection....mnemonic", "", "", "", ""},
257             {"No deadlock detected", "", "", "", ""},
258             {"Non-Heap", "", "", "", ""},
259             {"Non-Heap Memory Usage", "", "", "", ""},
260             {"Notification", "", "", "", ""},
261             {"Notification buffer", "", "", "", ""},
262             {"Notifications", "", "", "", ""},
263             {"NotifTypes", "", "", "", ""},
264             {"Number of Loaded Classes", "", "", "", ""},
265             {"Number of processors", "", "", "", ""},
266             {"Number of Threads", "", "", "", ""},
267             {"ObjectName", "", "", "", ""},
268             {"Operating System", "", "", "", ""},
269             {"Operation", "", "", "", ""},
270             {"Operation invocation", "", "", "", ""},
271             {"Operation return value", "", "", "", ""},
272             {"Operations", "", "", "", ""},
273             {"Overview", "", "", "", ""},
274             {"OverviewPanel.plotter.accessibleName", "PhonyPlotter", "", "", ""},
275             {"Parameter", "", "", "", ""},
276             {"Password: ", "", "", "", ""},
277             {"Password: .mnemonic", "", "", "", ""},
278             {"Password.accessibleName", "", "", "", ""},
279             {"Peak", "", "", "", ""},
280             {"Perform GC", "", "", "", ""},
281             {"Perform GC.mnemonic", "", "", "", ""},
282             {"Perform GC.toolTip", "", "", "", ""},
283             {"Plotter.accessibleName", "", "", "", ""},
284             {"Plotter.accessibleName.keyAndValue", "Key", "Value", "", ""},
285             {"Plotter.accessibleName.noData", "", "", "", ""},
286             {"Plotter.saveAsMenuItem", "", "", "", ""},
287             {"Plotter.saveAsMenuItem.mnemonic", "", "", "", ""},
288             {"Plotter.timeRangeMenu", "", "", "", ""},
289             {"Plotter.timeRangeMenu.mnemonic", "", "", "", ""},
290             {"plot", "", "", "", ""},
291             {"Problem adding listener", "", "", "", ""},
292             {"Problem displaying MBean", "", "", "", ""},
293             {"Problem invoking", "", "", "", ""},
294             {"Problem removing listener", "", "", "", ""},
295             {"Problem setting attribute", "", "", "", ""},
296             {"Process CPU time", "", "", "", ""},
297             {"Readable", "", "", "", ""},
298             {"Reconnect", "", "", "", ""},
299             {"Remote Process:", "", "", "", ""},
300             {"Remote Process:.mnemonic", "", "", "", ""},
301             {"Remote Process.textField.accessibleName", "", "", "", ""},
302             {"remoteTF.usage", "", "", "", ""},
303             {"Restore All", "", "", "", ""},
304             {"Restore All.mnemonic", "", "", "", ""},
305             {"ReturnType", "", "", "", ""},
306             {"SeqNum", "", "", "", ""},
307             {"Size Bytes", 512, "", "", ""},
308             {"Size Gb", 512, "", "", ""},
309             {"Size Kb", 512, "", "", ""},
310             {"Size Mb", 512, "", "", ""},
311             {"Source", "", "", "", ""},
312             {"Stack trace", "", "", "", ""},
313             {"SummaryTab.headerDateTimeFormat", "", "", "", ""},
314             {"SummaryTab.pendingFinalization.label", "", "", "", ""},
315             {"SummaryTab.pendingFinalization.value", "ObjectCount", "", "", ""},
316             {"SummaryTab.tabName", "", "", "", ""},
317             {"SummaryTab.vmVersion",  "VMName", "VMVersion", "", ""},
318             {"ThreadTab.infoLabelFormat", "LiveCount", "PeakCount", "TotalCount", ""},
319             {"ThreadTab.threadInfo.accessibleName", "", "", "", ""},
320             {"ThreadTab.threadPlotter.accessibleName", "", "", "", ""},
321             {"Threads", "", "", "", ""},
322             {"Threshold", "", "", "", ""},
323             {"Tile", "", "", "", ""},
324             {"Tile.mnemonic", "", "", "", ""},
325             {"Time", "", "", "", ""},
326             {"Time Range:", "", "", "", ""},
327             {"Time Range:.mnemonic", "", "", "", ""},
328             {"TimeStamp", "", "", "", ""},
329             {"Total classes loaded", "", "", "", ""},
330             {"Total classes unloaded", "", "", "", ""},
331             {"Total compile time", "", "", "", ""},
332             {"Total Loaded", "", "", "", ""},
333             {"Total physical memory", "", "", "", ""},
334             {"Total swap space", "", "", "", ""},
335             {"Total threads started", "", "", "", ""},
336             {"Type", "", "", "", ""},
337             {"Unavailable", "", "", "", ""},
338             {"UNKNOWN", "", "", "", ""},
339             {"Unregister", "", "", "", ""},
340             {"Uptime", "", "", "", ""},
341             {"Usage Threshold", "", "", "", ""},
342             {"Used", "", "", "", ""},
343             {"Username: ", "", "", "", ""},
344             {"Username: .mnemonic", "", "", "", ""},
345             {"Username.accessibleName", "", "", "", ""},
346             {"UserData", "", "", "", ""},
347             {"Value", "", "", "", ""},
348             {"Vendor", "", "", "", ""},
349             {"Verbose Output", "", "", "", ""},
350             {"Verbose Output.toolTip", "", "", "", ""},
351             {"visualize", "", "", "", ""},
352             {"VM", "", "", "", ""},
353             {"VMInternalFrame.accessibleDescription", "", "", "", ""},
354             {"VM arguments", "", "", "", ""},
355             {"Virtual Machine", "", "", "", ""},
356             {"Window", "", "", "", ""},
357             {"Window.mnemonic", "", "", "", ""},
358             {"Writable", "", "", "", ""},
359             {"zz usage text", "PhonyName", "", "", ""},
360         };
361         //boolean verbose = false;
362         boolean verbose = true;
363 
364         long badLookups = 0;
365         System.out.println("Start...");
366         for (int ii = 0; ii < testData.length; ii++) {
367             String key = (String)testData[ii][0];
368 
369             if (key.endsWith(".mnemonic")) {
370                 String baseKey = key.substring(0, key.length() - ".mnemonic".length());
371                 int mnemonic = Resources.getMnemonicInt(baseKey);
372                 if (mnemonic == 0) {
373                     badLookups++;
374                     System.out.println("****lookup failed for key = " + key);
375                 } else {
376                     if (verbose) {
377                         System.out.println("    mnemonic: " + KeyEvent.getKeyText(mnemonic));
378                     }
379                 }
380                 continue;
381             }
382 
383             String ss = Resources.getText(key,
384                                           testData[ii][1],
385                                           testData[ii][2],
386                                           testData[ii][3],
387                                           testData[ii][4]);
388             if (ss.startsWith("missing resource key")) {
389                 badLookups++;
390                 System.out.println("****lookup failed for key = " + key);
391             } else {
392                 if (verbose) {
393                     System.out.println("  " + ss);
394                 }
395             }
396         }
397         if (badLookups > 0) {
398             throw new Error ("Resource lookup failed " + badLookups +
399                              " time(s); Test failed");
400         }
401         System.out.println("...Finished.");
402     }
403 }